package ${package}.modules.${moduleName}.service<#if subModuleName??>.${subModuleName}</#if>.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import ${package}.common.base.service.impl.CrudServiceImpl;
import ${package}.modules.${moduleName}.dao<#if subModuleName??>.${subModuleName}</#if>.${ClassName}Dao;
import ${package}.modules.${moduleName}.dto<#if subModuleName??>.${subModuleName}</#if>.${ClassName}DTO;
import ${package}.modules.${moduleName}.entity<#if subModuleName??>.${subModuleName}</#if>.${ClassName}Entity;
import ${package}.modules.${moduleName}.service<#if subModuleName??>.${subModuleName}</#if>.${ClassName}Service;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
* ${tableComment}
*
* @author ${author} ${email}
* @since ${version} ${date}
*/
@Service
public class ${ClassName}ServiceImpl extends CrudServiceImpl<${ClassName}Dao, ${ClassName}Entity, ${ClassName}DTO> implements ${ClassName}Service {

    @Override
    public QueryWrapper<${ClassName}Entity> getWrapper(Map<String, Object> params) {
        QueryWrapper<${ClassName}Entity> wrapper = new QueryWrapper<>();
    <#assign hasDateField = false/>
    <#assign hasDateTimeField = false/>
    <#list queryList as field>
    <#if field.queryFormType == 'date'>
    <#assign hasDateField = true/>
    </#if>
    <#if field.queryFormType == 'datetime'>
    <#assign hasDateTimeField = true/>
    </#if>
    </#list>
    <#if hasDateField || hasDateTimeField>
    <#if hasDateField>
        String startDate = (String) params.get("startDate");
        String endDate = (String) params.get("endDate");
    </#if>
    <#if hasDateTimeField>
        String startDateTime = (String) params.get("startDateTime");
        String endDateTime = (String) params.get("endDateTime");
    </#if>
    </#if>
    <#list queryList as field>
    <#if field.queryFormType == 'date' || field.queryFormType == 'datetime'>
        wrapper.gt(StringUtils.isNotBlank(startDate), "${field.fieldName}", startDate);
        wrapper.lt(StringUtils.isNotBlank(endDate), "${field.fieldName}", endDate);
    <#else>
            String ${field.attrName} = (String)params.get("${field.attrName}");
    <#switch field.queryType>
    <#case "=">
        wrapper.eq(StringUtils.isNotBlank(${field.attrName}), "${field.fieldName}", ${field.attrName});
    <#break>
    <#case "!=">
        wrapper.ne(StringUtils.isNotBlank(${field.attrName}), "${field.fieldName}", ${field.attrName});
            <#break>
    <#case ">">
        wrapper.gt(StringUtils.isNotBlank(${field.attrName}), "${field.fieldName}", ${field.attrName});
            <#break>
    <#case ">=">
        wrapper.ge(StringUtils.isNotBlank(${field.attrName}), "${field.fieldName}", ${field.attrName});
            <#break>
    <#case "<">
        wrapper.lt(StringUtils.isNotBlank(${field.attrName}), "${field.fieldName}", ${field.attrName});
            <#break>
    <#case "<=">
        wrapper.le(StringUtils.isNotBlank(${field.attrName}), "${field.fieldName}", ${field.attrName});
            <#break>
    <#case "like">
        wrapper.like(StringUtils.isNotBlank(${field.attrName}), "${field.fieldName}", ${field.attrName});
            <#break>
    <#case "left like">
        wrapper.likeLeft(StringUtils.isNotBlank(${field.attrName}), "${field.fieldName}", ${field.attrName});
            <#break>
    <#case "right like">
        wrapper.likeRight(StringUtils.isNotBlank(${field.attrName}), "${field.fieldName}", ${field.attrName});
            <#break>
    <#default>
        wrapper.ne(StringUtils.isNotBlank(${field.attrName}), "${field.fieldName}", ${field.attrName});
    </#switch>
    </#if>
    </#list>
        return wrapper;
    }
}
